<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%collection_task}}".
 *
 * @property int $id
 * @property int $template_id
 * @property string $task_name
 * @property string $task_status
 * @property int $created_at
 * @property int $updated_at
 * @property string $req_json
 * @property string $task_id
 *
 * @property CollectionResultPush[] $collectionResultPushes
 * @property CollectionTemplate $template
 */
class CollectionTask extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%collection_task}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['template_id', 'task_name', 'task_status', 'created_at', 'updated_at'], 'required'],
            [['template_id', 'created_at', 'updated_at'], 'integer'],
            [['req_json'], 'string'],
            [['task_name', 'task_id'], 'string', 'max' => 50],
            [['task_status'], 'string', 'max' => 20],
            [['task_name'], 'unique'],
            [['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => CollectionTemplate::className(), 'targetAttribute' => ['template_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'template_id' => Yii::t('app', 'Template ID'),
            'task_name' => Yii::t('app', 'Task Name'),
            'task_status' => Yii::t('app', 'Task Status'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'req_json' => Yii::t('app', 'Req Json'),
            'task_id' => Yii::t('app', 'Task ID'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCollectionResultPushes()
    {
        return $this->hasMany(CollectionResultPush::className(), ['task_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTemplate()
    {
        return $this->hasOne(CollectionTemplate::className(), ['id' => 'template_id']);
    }
}
